package org.jeecg.modules.wmhb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.jeecg.common.constant.UserConstant;
import org.jeecg.modules.wmhb.entity.WmItem;
import org.jeecg.modules.wmhb.entity.WmProductRecpt;
import org.jeecg.modules.wmhb.entity.WmProductSale;
import org.jeecg.modules.wmhb.mapper.WmProductSaleMapper;
import org.jeecg.modules.wmhb.service.IWmProductSaleService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Description: 销售出库记录表
 * @Author: jeecg-boot
 * @Date:   2024-08-31
 * @Version: V1.0
 */
@Service
public class WmProductSaleServiceImpl extends ServiceImpl<WmProductSaleMapper, WmProductSale> implements IWmProductSaleService {
    @Override
    public List<WmProductSale> queryListByWmTaskId(String wmTaskId){
        LambdaQueryWrapper<WmProductSale> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmProductSale::getWmTaskId, wmTaskId);
        List<WmProductSale> wmProductSaleList = list(queryWrapper);
        return wmProductSaleList;
    };

    @Override
    public void arriveConfirmByIdList(List<String> idList){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String arriveTime = format.format(new Date());
        LambdaUpdateWrapper<WmProductSale> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(WmProductSale::getStatus, UserConstant.PRODUCT_SALE_STATUS_ARRIVED)
                .set(WmProductSale::getArriveTime, arriveTime)
                .in(WmProductSale::getId, idList);
        update(null, updateWrapper);
    };

    @Override
    public void arriveByWmTaskId(String wmTaskId){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String arriveTime = format.format(new Date());
        LambdaUpdateWrapper<WmProductSale> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(WmProductSale::getStatus, UserConstant.PRODUCT_SALE_STATUS_ARRIVED)
                .set(WmProductSale::getArriveTime, arriveTime)
                .eq(WmProductSale::getWmTaskId, wmTaskId);
        update(null, updateWrapper);
    };
}
